package com.jiuyou.clientController.mall.coupons;

import com.jiuyou.clientController.base.ClientBaseController;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.shopping.domain.MallCouponsMember;
import com.ruoyi.shopping.domain.MallProduct;
import com.ruoyi.shopping.service.IMallCouponsMemberService;
import com.ruoyi.shopping.service.IMallProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author chengliang
 * @date 2022/7/15
 **/
@RestController
@RequestMapping("/client/mall/coupons")
public class MallCouponsMemberClientController extends ClientBaseController {
    @Autowired
    private IMallCouponsMemberService cmService;

    @Autowired
    private IMallProductService productService;
    @PostMapping("/getMineCoupons/{productId}")
    private AjaxResult getMineCoupons(@PathVariable Long productId){

        MallCouponsMember mallCouponsMember = new MallCouponsMember();
        mallCouponsMember.setMemberId(getLoginMemberId());
        MallProduct product = productService.selectMallProductById(productId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("classify",product.getClassifyId());
        map.put("product",product.getId());
        mallCouponsMember.setParams(map);
        mallCouponsMember.setCanUseState(DicConstants.SYS_Y.getCode());
        mallCouponsMember.setUseState(DicConstants.SYS_N.getCode());
//        mallCouponsMember.setMinPrice(product.getCurrentPrice());

        List<MallCouponsMember> mallCouponsMembers = cmService.selectMineCoupons(mallCouponsMember);
//        List<MallCouponsMember> mallCouponsMembers = cmService.selectCanUseList(mallCouponsMember);
        return AjaxResult.success(mallCouponsMembers);
    }

}
